﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;

namespace GUI
{
    public partial class uc_PhanQuyen : DevExpress.XtraEditors.XtraUserControl
    {
        NhatKy_BLL  nk=new NhatKy_BLL();
        public uc_PhanQuyen()
        {
            InitializeComponent();
        }

        private void uc_PhanQuyen_Load(object sender, EventArgs e)
        {
            treeView1.CheckBoxes = true;
            DataTable nodeperent;
            DataTable nodechild;
            nodeperent = nk.TaoBang("select TenLinhVuc from DM_LinhVuc");
            for (int i = 0; i < nodeperent.Rows.Count; i++)
            {
                treeView1.Nodes.Add(nodeperent.Rows[i][0].ToString());
                treeView1.Nodes[i].Tag = "1";
                nodechild = nk.TaoBang("Select NhanDe from DM_LinhVuc as b left join TaiLieu as a on a.MaLinhVuc=b.MaLinhVuc where b.TenLinhVuc=N'" + nodeperent.Rows[i][0] + "'");
                for (int j = 0; j < nodechild.Rows.Count; j++)
                {
                    try
                    {
                        treeView1.Nodes[i].Nodes.Add(nodechild.Rows[j][0].ToString());
                        treeView1.Nodes[i].Nodes[j].Tag = "2";
                    }
                    catch (Exception)
                    { }
                }
            }
            ////Adds new node as a child node of the currently selected node. 
            //treeView1.CheckBoxes = true;
            //TreeNode newNode = new TreeNode("Text for new node");
            //treeView1.Nodes.Add(newNode);
            //TreeNode newNode1 = new TreeNode("Text for new node 1");
            //treeView1.Nodes.Add(newNode1);
            //TreeNode newNode2 = new TreeNode("Welcome to TreeView Control Tutorial");
            //treeView1.Nodes.Add(newNode2);

            //TreeNode node1 = new TreeNode("C#");
            //TreeNode node2 = new TreeNode("VB.NET");
            //TreeNode node3 = new TreeNode("C++");
            //TreeNode[] array = new TreeNode[] { node1, node2, node3 };
            //TreeNode programmingLanguage = new TreeNode("Programming Language", array);
            //treeView1.Nodes.Add(programmingLanguage);
            //}
        }

        private void barEditItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barButtonItem1.Enabled = false;
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Determine by checking the Text property. 
            
            MessageBox.Show(e.Node.Text);
        }
    }
}
